//============================================================
// Producnt name:		Wz
// Version: 			1.0
// Coded by:			Wz (13066628480@163.com)
// Auto generated at: 	2016/10/9 10:22:04
//============================================================

using System;
using System.Collections.Generic;
using System.Text;
using Cloud.Model;
using System.Data.SqlClient;
using System.Data;
namespace Cloud.DAL
{
	public static class ROLESService
	{
		#region SqlCommandText
		private const string Save_CommandText = "insert into ROLES values(@ROLE_ID,@ROLE_NAME,@SYSTEM_ID,@LOCK)";
		private const string Update_CommandText = "Update ROLES set ROLE_NAME = @ROLE_NAME,SYSTEM_ID = @SYSTEM_ID,LOCK = @LOCK where ROLE_ID = @ROLE_ID";
		private const string Delete_CommandText = "delete from ROLES where ROLE_ID = @ROLE_ID";
		private const string FindAll_CommandText = "select * from ROLES";
		private const string FindById_CommandText = "select * from ROLES where ROLE_ID=@ROLE_ID";
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region Save
		public static int Save(ROLES rOLES)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@ROLE_ID",SqlDbType.VarChar),
				new SqlParameter("@ROLE_NAME",SqlDbType.VarChar),
				new SqlParameter("@SYSTEM_ID",SqlDbType.VarChar),
				new SqlParameter("@LOCK",SqlDbType.VarChar)
				};
			pars[0].Value=rOLES.ROLE_ID;
			pars[1].Value=rOLES.ROLE_NAME;
			pars[2].Value=rOLES.SYSTEM_ID;
			pars[3].Value=rOLES.LOCK;
	
			return DBHelper.ExecuteNonQuery(Save_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Update
		public static int Update(ROLES rOLES)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@ROLE_ID",SqlDbType.VarChar),
				new SqlParameter("@ROLE_NAME",SqlDbType.VarChar),
				new SqlParameter("@SYSTEM_ID",SqlDbType.VarChar),
				new SqlParameter("@LOCK",SqlDbType.VarChar)
				};
			pars[0].Value=rOLES.ROLE_ID;
			pars[1].Value=rOLES.ROLE_NAME;
			pars[2].Value=rOLES.SYSTEM_ID;
			pars[3].Value=rOLES.LOCK;
	
			return DBHelper.ExecuteNonQuery(Update_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Delete
		public static int Delete(ROLES rOLES)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@ROLE_ID",SqlDbType.VarChar)
				};
			pars[0].Value=rOLES.ROLE_ID;
	
			return DBHelper.ExecuteNonQuery(Delete_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region FindAll
		public static IList<ROLES> FindAll()
		{
			return CommonQuery(FindAll_CommandText,CommandType.Text,null);
		}
		#endregion
		
		#region FindById
		public static ROLES FindById(String rOLE_ID)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@rOLE_ID",SqlDbType.VarChar)
			};	
			pars[0].Value = rOLE_ID;
			IList<ROLES> list = CommonQuery(FindById_CommandText,CommandType.Text,pars);
			return list.Count > 0 ? list[0] : null;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region CommonQuery
		private static IList<ROLES> CommonQuery(string commandText, CommandType cmdType, SqlParameter[] pars)
		{
			IList<ROLES> list = new List<ROLES>();
			ROLES rOLES = null;
			
			using (SqlDataReader reader = DBHelper.ExecuteQuery(commandText,cmdType,pars))
           	{
				while(reader.Read())
				{
					rOLES = new ROLES();
                    if (reader["ROLE_ID"]==null)
                    {
                        rOLES.ROLE_ID = "";
                    }
                    else
                    {
                        rOLES.ROLE_ID = Convert.ToString(reader["ROLE_ID"]);
                    }

                    if (reader["ROLE_NAME"]==null)
                    {
                        rOLES.ROLE_NAME = "";
                    }
                    else
                    {
                        rOLES.ROLE_NAME = Convert.ToString(reader["ROLE_NAME"]);
                    }

                    if (reader["SYSTEM_ID"]==null)
                    {
                        rOLES.SYSTEM_ID = "";
                    }
                    else
                    {
                        rOLES.SYSTEM_ID = Convert.ToString(reader["SYSTEM_ID"]);
                    }

                    if (reader["LOCK"]==null)
                    {
                        rOLES.LOCK = "";
                    }
                    else 
                    {
                        rOLES.LOCK = Convert.ToString(reader["LOCK"]);
                    }
					
					
					list.Add(rOLES);
				}
            }
            return list;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
	}
}



